package lyh0414;



import java.util.*;
interface IntegerStack{
	public Integer push(Integer item);
	public Integer pop();
	public Integer peek();
	public boolean empty();
	public int size();
}
class ArrayListIntegerStack implements IntegerStack {
    
	private List<Integer> list;
	public ArrayListIntegerStack(){
		list=new ArrayList<Integer>();
	}
	@Override
	public String toString() {
		return list.toString();
	}
	@Override
	public Integer push(Integer item) {
		if(item==null) return null;
		list.add(item);
		return item;
	}
	@Override
	public Integer pop() {
		if(list.isEmpty()) return null;
		return list.remove(list.size()-1);
	} 
	@Override
	public Integer peek() {
		if(list.isEmpty()) return null;
		return list.get(list.size()-1);
	}
	@Override
	public boolean empty() {
		if(list.isEmpty()) return true;
		else return false;
	} 
	@Override
	public int size() {
		
		return list.size();
	} 
}

public class Main0260501{

	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);
		ArrayListIntegerStack Stack = new ArrayListIntegerStack();
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			Integer number = in.nextInt();
			System.out.println(Stack.push(number));
		}
		System.out.print(Stack.peek() + "," + Stack.empty() + "," + Stack.size() + "\n");
		System.out.println(Stack.toString());
		int x = in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(Stack.pop());
		}
		System.out.print(Stack.peek() + "," + Stack.empty() + "," + Stack.size() + "\n");
		System.out.println(Stack.toString());
	}
 }


